import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";

var _dec, _class;

import React, { PureComponent } from 'react';
import { Table, Tag } from 'antd';
import { Bind } from 'lodash-decorators';
import "./index.less";
import intl from 'utils/intl';
var prefix = 'cpfm.login.audit.model';
var ListTable = (_dec = Bind(), (_class = /*#__PURE__*/function (_PureComponent) {
  _inherits(ListTable, _PureComponent);

  var _super = _createSuper(ListTable);

  function ListTable() {
    _classCallCheck(this, ListTable);

    return _super.apply(this, arguments);
  }

  _createClass(ListTable, [{
    key: "onCell",
    value: function onCell() {
      return {
        style: {
          overflow: 'hidden',
          maxWidth: 200,
          textOverflow: 'ellipsis',
          whiteSpace: 'nowrap'
        },
        onClick: function onClick(e) {
          var target = e.target;

          if (target.style.whiteSpace === 'normal') {
            target.style.whiteSpace = 'nowrap';
          } else {
            target.style.whiteSpace = 'normal';
          }
        }
      };
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props = this.props,
          loading = _this$props.loading,
          dataSource = _this$props.dataSource,
          pagination = _this$props.pagination,
          _onChange = _this$props.onChange;
      var columns = [{
        title: intl.get("".concat(prefix, ".auditTypeMeaning")).d('审计类型'),
        width: 150,
        dataIndex: 'auditTypeMeaning',
        render: function render(_, record) {
          var color = '';

          switch (record.auditType) {
            case 'LOGIN_FAILURE':
              color = 'red';
              break;

            case 'LOGIN':
              color = 'green';
              break;

            case 'LOGOUT':
              color = 'orange';
              break;

            default:
              color = 'blue';
              return;
          }

          return /*#__PURE__*/React.createElement(Tag, {
            color: color
          }, record.auditTypeMeaning);
        }
      }, {
        title: intl.get("".concat(prefix, ".account")).d('账号'),
        width: 200,
        dataIndex: 'loginName'
      }, {
        title: intl.get("".concat(prefix, ".name")).d('名称'),
        width: 200,
        dataIndex: 'userName'
      }, {
        title: intl.get("".concat(prefix, ".phone")).d('手机号'),
        width: 200,
        dataIndex: 'phone'
      }, {
        title: intl.get("".concat(prefix, ".login.time")).d('登录时间'),
        width: 200,
        dataIndex: 'loginDate'
      }, {
        title: intl.get("".concat(prefix, ".login.address")).d('登录地址'),
        width: 200,
        dataIndex: 'loginIp'
      }, {
        title: intl.get("".concat(prefix, ".login.device")).d('登录设备'),
        width: 200,
        dataIndex: 'loginDevice'
      }, {
        title: intl.get("".concat(prefix, ".login.loginMessage")).d('登录信息'),
        width: 200,
        dataIndex: 'loginMessage',
        onCell: this.onCell
      }];
      return /*#__PURE__*/React.createElement(Table, {
        bordered: true,
        rowKey: "order",
        loading: loading,
        columns: columns,
        dataSource: dataSource.map(function (item, index) {
          return _objectSpread(_objectSpread({}, item), {}, {
            order: index + 1
          });
        }),
        pagination: pagination,
        onChange: function onChange(page) {
          return _onChange(page);
        }
      });
    }
  }]);

  return ListTable;
}(PureComponent), (_applyDecoratedDescriptor(_class.prototype, "onCell", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "onCell"), _class.prototype)), _class));
export { ListTable as default };